package com.baidu.config;

import com.baidu.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//@Configuration
public class MvcConfig implements WebMvcConfigurer {
    // 注册拦截器
    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();//创建一个新的MyInterceptor实例并返回
    }

    // 将拦截器添加到拦截器链，指定拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor())  // 添加拦截器到registry中
                .addPathPatterns("/**")  // 拦截所有路径
                .excludePathPatterns("/warehouse/login") // 不拦截/index路径
                .excludePathPatterns("/captcha/captchaImage"); // 不拦截/index路径
    }
}
